package com.hong.chapter5;

/**
 * Created by hong on 2018/6/3.
 * 守护线程
 */
public class ThreadJoin3 {
    public static void main(String[] args) throws InterruptedException {
        long startTimestamp = System.currentTimeMillis();
        Thread t1 = new Thread(new CaptureRunnable("M1",1000L) );
        Thread t2 = new Thread(new CaptureRunnable("M1",5000L) );
        Thread t3 = new Thread(new CaptureRunnable("M1",10000L) );
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        long endTimestamp = System.currentTimeMillis();
        System.out.printf("save data begin timestamp is:%s,end timestamp is:%s\n ",startTimestamp,endTimestamp);
    }


}


class CaptureRunnable implements  Runnable{

    private String machineName;

    private long spendTime;


    public CaptureRunnable(String machineName,long spendTime){
        this.machineName = machineName;
        this.spendTime=spendTime;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(spendTime);
            System.out.println(machineName+" completed data capture and successfully. ");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}